/**
 * 更新VNodeDatas中的className相关
 */

import {checkIsVnode} from './vnode'

export function updateDataset(oldVnode,vnode){

    if(!checkIsVnode([oldVnode,vnode])) return

     let elm=vnode.elm,
     oldAttrs=oldVnode.data&&oldVnode.data.className||{},
     attrs=vnode.data&&vnode.data.className||{}

     if(!oldAttrs&&!attrs) return
     if(oldAttrs===attrs) return

     /**remove previous and no need attrs */
     for(let key in oldAttrs){
        if(!attrs[key]) elm.removeAttribute('data-'+key)
     }

     /**update modified attrs and add new attrs */
     for(let key in attrs){
        const cur=attrs[key],
        old=oldAttrs[key]
        
        if(old!==cur){
          if(elm.dataset){
             elm.dataset=attrs[key]
          }else  elm.setAttribute('data-'+key)
        }
        
     }


     
 }